<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="${ctxPath}/assets/expand/images/favicon.ico" rel="icon">
    <title>${systemName}</title>
    <link rel="stylesheet" href="${ctxPath}/assets/common/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/common/module/admin.css"/>
</head>

<body class="layui-layout-body">

<div class="layui-layout layui-layout-admin">

    <!-- 头部 -->
    @include("/common/_header.html"){}

    <!-- 侧边栏 -->
    @include("/common/_sidebar.html"){}

    <!-- 主体部分 -->
    @include("/common/_body.html"){}

    <!-- 底部 -->
    @include("/common/_footer.html"){}

</div>

<!-- 加载动画，移除位置在common.js中 -->
@include("/common/loading.html"){}

@/* 加入contextPath属性和session超时的配置 */
<script type="text/javascript">
    var Feng = {
        ctxPath: "",
        addCtx: function (ctx) {
            if (this.ctxPath === "") {
                this.ctxPath = ctx;
            }
        }
    };
    Feng.addCtx("${ctxPath}");
</script>
<script type="text/javascript" src="${ctxPath}/assets/common/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/common/js/common.js"></script>

<script>
    layui.use(['ax','layer', 'element', 'admin', 'index'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var admin = layui.admin;
        var index = layui.index;
        var $ax = layui.ax;

        //通知
        Notification.requestPermission();

        var userLevel = ${user.userLevel}

        var menuPath;
        var menuName;

        menuPath = '${ctxPath}/chart';
        menuName = '<i class="layui-icon layui-icon-app"></i>';

        var layIndex;
        if(userLevel!=1){
            //不是省级用户，跳转任务提醒页面
            menuPath = '${ctxPath}/tip';
            //查询是否有当月前未完成的任务
            var ajax = new $ax(Feng.ctxPath + "/tip/notification", function (data) {
                if(data.count>0){
                    layIndex = layer.open({
                        type: 1
                        ,title: false //不显示标题栏
                        ,closeBtn: false
                        ,area: '700px;'
                        ,shade: 0.8
                        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                        ,btn: ['我知道了']
                        ,btnAlign: 'c'
                        ,moveType: 1 //拖拽模式，0或者1
                        ,content: '<div style="padding: 50px;font-size: 32px; line-height: 45px; background-color: #393D49; color: #fff; font-weight: 300;">您当前还有以下月份任务未完成：<br>'+data.months+'<br><br> 请尽快完成。 </div>'
                        ,success: function(layero){
//                            var btn = layero.find('.layui-layer-btn');
//                            btn.find('.layui-layer-btn0').attr({
//                                href: 'http://www.layui.com/'
//                                ,target: '_blank'
//                            });
                            menuPath = '${ctxPath}/deal';
                        }
                    });

                    var notification = new Notification('任务提醒',{
                        body:'您在'+data.months+'有任务未完成',
                        icon: Feng.ctxPath + '/assets/expand/images/favicon.ico'
                    })

                    notification.onclick = function () {
                        if(layIndex!=undefined){
                            layer.close(layIndex)
                        }
                    }
                    notification.onclose = function () {
                        if(layIndex!=undefined){
                            layer.close(layIndex)
                        }
                    }
                    notification.onshow = function () {
                        var audio = new Audio();
                        audio.src = Feng.ctxPath + "/assets/expand/audio/tip.mp3";
                        audio.play();
                    }
                }
            }, function (data) {
                Feng.error("查询失败！" + data.responseJSON.message)
            });
            ajax.start();
        }

        // 默认加载主页
        index.loadHome({
            menuPath: menuPath,
            menuName: menuName
        });

        // 修改密码点击事件
        $('#setPsw').click(function () {
            admin.open({
                id: 'pswForm',
                type: 2,
                title: '修改密码',
                shade: 0,
                content: '${ctxPath}/system/user_chpwd'
            });
        });

        // 退出登录点击事件
        $('#btnLogout').click(function () {
            layer.confirm('确定退出登录？', {
                skin: 'layui-layer-admin'
            }, function () {
                window.location.href = "${ctxPath}/logout";
            });
        });

    });
</script>
</body>

</html>